home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Question on stingizing
- Date: 04 Mar 1996 00:24:12 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar3172412@qcd.lanl.gov>
- References: <4hda43$f15@skivs.ski.org>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: gt@ns.oon.or.jp's message of Sun, 03 Mar 1996 23:26:38 GMT
-
- In article <4hda43$f15@skivs.ski.org>
- gt@ns.oon.or.jp (Gemini Thunder) writes:
-
- GT: I have looked over this problem, but can not figure out the why of
- GT: it. I don't have a copy of the Standard, but I have read the FAQ
- GT: (11.17), but it does not give the why of it either....
- GT: Why is this necessary:
- GT:
- GT: #define A Hello
- GT: #define s(x) #x
- GT: #define ss(x) s(x) /* why this circumvention for #defined ?? */
-
- Roughly because # prohibits expansion of its parameter: macro
- arguments are otherwise (i.e. unless # and ## overrides this rule)
- expanded completely before substitution. i.e. with the # operator you
- get the stringized version of the unexpanded argument to the macro.
-
- ss(A) now expands in the following stages:
-
- ss(A) has argument A which is first expanded
- A --> Hello
- and then replaced into the pattern which is then expanded:
- ss(A) --> s(Hello) --> "Hello"
-
- Whereas
-
- s(A) --> "A"
-
- because argument A is not expanded before substitution.
-
- To take a more complicated example, given ss(ss(s(A))),
-
- s(A) --> "A"
- ss(s(A)) --> s("A") --> "\"A\""
- ss(ss(s(A))) --> s("\"A\"") --> "\"\\\"A\\\"\""
-
- If you understand the above, you understand macro expansion better
- than most beginners do.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-